﻿<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Dictionary"
                  targetNamespace="http://dzonny.cz/xml/Dictionary"
                  elementFormDefault="qualified"
                  xmlns="http://dzonny.cz/xml/Dictionary"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  xmlns:simple="http://dzonny.cz/xml/DictionarySimple"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://dzonny.cz/xml/DictionarySimple http://dzonny.cz/xml/DictionarySimple.xsd" 
                  xmlns:d="http://dzonny.cz/xml/Dictionary"
                  >
    <xs:annotation>
        <xs:documentation>
            This is schema of export-import file used by the ĐŘječnik dictionary engine.
            See http://codeplex.com/DjRjecnik for details.
            
            The root element of dictionary file should be &lt;Dictionary> (see below).
            
            This idctionary schema is recomended format for sharing, importing and exporting
            dictionaries while using the ĐŘječnik dictionary engine.
        </xs:documentation>
    </xs:annotation>
    <xs:import namespace="http://dzonny.cz/xml/DictionarySimple"/>
    
    <!--Root element-->
    <xs:element name="Dictionary">
        <xs:annotation>
            <xs:documentation>Root element of dictionary</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence minOccurs="1" maxOccurs="1">
                <xs:element ref="simple:info"/>
                <xs:sequence minOccurs="1" maxOccurs="1">
                    <xs:element minOccurs="1" maxOccurs="unbounded" ref="word"/>
                    <xs:element minOccurs="1" maxOccurs="unbounded" ref="tr"/>
                    <xs:element minOccurs="0" maxOccurs="unbounded" ref="rel"/>
                </xs:sequence>
            </xs:sequence>
        </xs:complexType>

        <!--Constraints-->
        <xs:key name="WordUniqueID">
            <xs:selector xpath="d:word"/>
            <xs:field xpath="@ID"/>
        </xs:key>
        <xs:key name="UniqueTranslation">
            <xs:selector xpath="d:tr"/>
            <xs:field xpath="@w1"/>
            <xs:field xpath="@w2"/>
        </xs:key>
        <xs:key name="UniqueRelation">
            <xs:selector xpath="d:rel"/>
            <xs:field xpath="@From"/>
            <xs:field xpath="@To"/>
        </xs:key>
        
        <xs:keyref name="TrnslWord1" refer="WordUniqueID">
            <xs:selector xpath="d:tr"/>
            <xs:field xpath="@w1"/>
        </xs:keyref>
        <xs:keyref name="TrnslWord2" refer="WordUniqueID">
            <xs:selector xpath="d:tr"/>
            <xs:field xpath="@w2"/>
        </xs:keyref>
        <xs:keyref name="RelFrom" refer="WordUniqueID">
            <xs:selector xpath="d:rel"/>
            <xs:field xpath="@From"/>
        </xs:keyref>
        <xs:keyref name="RelTo" refer="WordUniqueID">
            <xs:selector xpath="d:rel"/>
            <xs:field xpath="@To"/>
        </xs:keyref>
    </xs:element>
    
    <!--Simple types-->
    <xs:simpleType name="Lang">
        <xs:annotation>
            <xs:documentation>Defines the language of word</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:unsignedByte">
            <xs:enumeration value="1">
                <xs:annotation>
                    <xs:documentation>Word is in language 1 of dictionary</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="2">
                <xs:annotation>
                    <xs:documentation>Word is in language 2 of dictionary</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    
    <!--Word-->
    <xs:element name="word">
        <xs:annotation>
            <xs:documentation>
                Represents one single word.
                Each word should have at least 1 translation (not verified).
            </xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence minOccurs="0" maxOccurs="1">
                <xs:element name="note" type="xs:normalizedString">
                    <xs:annotation>
                        <xs:documentation>Any note to word</xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="Native" use="required" type="xs:token">
                <xs:annotation>
                    <xs:documentation>Text that represents word in native script of language the word belongs to</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="Latin" use="optional" type="xs:token">
                <xs:annotation>
                    <xs:documentation>Optional transliteration of word into latin</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="Lang" use="required" type="Lang">
                <xs:annotation>
                    <xs:documentation>Language of word. Specifies if word belongs to language 1 or 2 of a dictionary</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="ID" use="required" type="xs:unsignedInt">
                <xs:annotation>
                    <xs:documentation>
                        Unique ID of word.
                        ID is integral number used to reffer to the word.
                        Words' IDs must start at 0 for first word and raise by 1 for each next word (not verifyed by this schema but may be required by dictionary engine import logic).
                    </xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="Type" use="optional" type="simple:wordtype">
                <xs:annotation>
                    <xs:documentation>Specifies grammatical type of the word (optional)</xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>        
    </xs:element>

    <!--Translation-->
    <xs:element name="tr">
        <xs:annotation>
            <xs:documentation>
                Represents a translation.
                Translation relation between two word from different language.
                Each translation must be unique.
                </xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute name="w1" type="xs:unsignedInt" use="required">
                <xs:annotation>
                    <xs:documentation>
                        Reference to word in language 1 of the dictionary.
                        (It is not verified by this schema if this is reference to word in language 1, but it should be verified by dictionary engine import logic.)
                    </xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="w2" type="xs:unsignedInt" use="required">
                <xs:annotation>
                    <xs:documentation>
                        Reference to word in laguage 2 of the dictionary.
                        (It is not verified by this schema if this is reference to word in language 2, but it should be verified by dictionary engine import logic.)
                    </xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    
    <!--Relation-->
    <xs:element name="rel">
        <xs:annotation>
            <xs:documentation>
                Represents one-way (exists only in direction From - To in which is defined - opposite direction can be retrieved by dictionary engine as special kind of back reference) relation between two words in same language (it is not verified by this schema if relation is established within laguage but it should be verified by dictionary engine import logic).
                Each relation must have unique From To pair.
            </xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute name="From" type="xs:unsignedInt" use="required">
                <xs:annotation>
                    <xs:documentation>Reference to word from which the relation is established</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="To" type="xs:unsignedInt" use="required">
                <xs:annotation>
                    <xs:documentation>Reference to word to which the relation is established</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="type" type="simple:relation" use="required">
                <xs:annotation>
                    <xs:documentation>Type of the relation</xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
</xs:schema>

